package com.tkmybatis.hfy.config.web;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;


@Configuration
public class WebConfigBeans {
	
		@Autowired
	    private RequestMappingHandlerAdapter handlerAdapter;

	    /**
	     * 增加字符串转日期的功能
	     */
	    @PostConstruct
	    public void initEditableValidation() {
	    	
	        ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) handlerAdapter
	            .getWebBindingInitializer();
	        if (initializer != null && initializer.getConversionService() != null) {
	            GenericConversionService genericConversionService = (GenericConversionService) initializer
	                .getConversionService();
	            if(genericConversionService != null) {
	            	genericConversionService.addConverter(new StringToDateConverter());
	            }
	        }

	    }

}
